<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<% 
	String webpath = request.getContextPath(); 
	String path =  request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + webpath +"/";
	request.setAttribute("path", path);
%>
 <div class="r_location">
	<i class="r_txtico"></i> 微信配置管理 &gt; 关键词管理&gt;新增关键词
</div>
<form id="add_func_form"  method="post"  action="cms/wechatkeyword/add">
 								<ul class="all_list">
		                            <li>
                   						<span class="all_title">关键词:</span>
	                                     <span><input  class="ui_input"  style="width:200px;" validator='{"label":"关键词","minLength":1,"maxLength":20}'  
	                                       id="keyName" name="keyName"/>
	                                    <font style="color: red;">*这里每填写一个关键字用（|） 竖线隔开</font></span>
                                	</li>
		                           <li>
		                            <span class="all_title">推送消息类型:</span>
		                            <span>
		                                 <select id="message_type"  class="ui_input" style="width: 200px;">
		                                     <option value="text" selected="selected">文本</option>
		                                     <option value="news">图文</option>
		                                 </select>
		                              </span>
		                           </li>
		                            <li>
                                <div class="span12 field-box" data-id="text">
                                    <span class="all_title">文本消息:<font style="color: red;">*</font></span>
                                    <textarea  rows="3" cols="60"  id="text"></textarea>
                                </div>
                                 </li>
		                            <li>
                                <div class="span12 field-box" data-id="news">
                                    <span class="all_title">标题:<font style="color: red;">*</font></span>
                                    <input class="ui_input" style="width:200px;" type="text" id="Title" name="Title"/>
                                </div>
                                 </li>
		                            <li>
                                <div class="span12 field-box" data-id="news">
                                    <span class="all_title">描述:<font style="color: red;">*</font></span>
                                    <input class="ui_input" style="width:500px;" type="text" id="Description" name="Description"/>
                                </div>
                                 </li>
		                            <li>
                                <div class="span12 field-box" data-id="news">
                                    <span class="all_title">图片地址:<font style="color: red;">*</font></span>
                                    <input class="ui_input" style="width:500px;" type="text" id="PicUrl" name="PicUrl"/>
                                </div>
                                 </li>
		                            <li>
                                <div class="span12 field-box" data-id="news">
                                    <span class="all_title">图文地址:<font style="color: red;">*</font></span>
                                    <input class="ui_input" style="width:500px;" type="text" id="Url" name="Url"/>
                                </div>
                                 </li>
		                            <li>
                                <div class="span12 field-box" >
                                    <span style="color: red;" id="error_message"></span>
                                </div>
                                 </li>
		                            <li>
					<span class="all_title"></span>
					<span> 
						<input type="button" id="save_button" value="保存" class="submit_btn m-r15 submitBtn">
					</span>
					</li>
                  </ul>
  </form>
    <script type="text/javascript">
        $(function () {

            // toggle form between inline and normal inputs
            var $buttons = $(".toggle-inputs button");
            var $form = $("form.new_user_form");
			$("#message_type").change(function(){
				var message_type = $("#message_type").val();
				if(message_type == "text"){
					$(document).find("div[data-id='news']").css("display","none");
					$(document).find("div[data-id='text']").css("display","");
				}else{
					$(document).find("div[data-id='text']").css("display","none");
					$(document).find("div[data-id='news']").css("display","");
				}
			});
			$("#message_type").change();
            $buttons.click(function () {
                var mode = $(this).data("input");
                $buttons.removeClass("active");
                $(this).addClass("active");

                if (mode === "inline") {
                    $form.addClass("inline-input");
                } else {
                    $form.removeClass("inline-input");
                }
            });
            $("#save_button").click(function(){
            	var message_type = $("#message_type").val();
            	var wechatName = 'wcfsywechat';
            	var keyName = $("#keyName").val();
            	if(keyName==null || keyName==""){
            		$("#error_message").text('');
            		$("#error_message").text("关键词不能为空！");
            		return false;
            	}
            	var param = {};
            	if(message_type == "text"){
            		var text = $("#text").val();
            		if(text==null || text==""){
            			$("#error_message").text("");
                		$("#error_message").text("文本消息不能为空！");
                		return false;
            		}
            		param = {
            				'wechatName' : wechatName,
            				'type':message_type,
            				'text':text,
            				'keyName':keyName
            		}
            	}else{
            		
                	var Title = $("#Title").val();
    				if(Title==null || Title==""){
    					$("#error_message").text("");
                		$("#error_message").text("标题不能为空！");
                		return false;
                	}
                	var Description = $("#Description").val();
    				if(Description==null || Description==""){
    					$("#error_message").text("");
                		$("#error_message").text("描述不能为空！");
                		return false;
                	}
                	var PicUrl = $("#PicUrl").val();
    				if(PicUrl==null || PicUrl==""){
    					$("#error_message").text("");
                		$("#error_message").text("图片地址不能不能为空！");
                		return false;
                	}
    				var Url = $("#Url").val();
    				if(Url==null || Url==""){
    					$("#error_message").text("");
                		$("#error_message").text("图文地址不能不能为空！");
                		return false;
                	}
    				
            		param = {
            				'wechatName' : wechatName,
            				'type':message_type,
            				'keyName':keyName,
            				'Title':Title,
            				'Description':Description,
            				'PicUrl':PicUrl,
            				'Url':Url,
            		}
            	}
				$.ajax({
           			type : "post",
           			dataType : 'json',
           			async: false,
           			url : '${path}cms/wechatkeyword/add',
           			data : param,
           			success : function(data){
           				if (data.success == 'succeed') {
    						art.dialog({icon: 'succeed',content: data.message,lock:true});
    						to_page("/cms/wechatkeyword/view/page");
    					} else {
    						art.dialog({icon: 'error',content: data.message,lock:true});
    					}
           			}
           		});
				 
            });
        });
    </script>